package com.jushu.storbox.view.dialog;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.jushu.storbox.LoginActivity;
import com.jushu.storbox.R;
import com.jushu.storbox.manager.ActivityTaskManager;
import com.jushu.storbox.util.LogUtil;

public class ExceptionPrompt {

	private final static String LOG_TAG = "ExceptionPrompt";

	public static void showException(int exceptionCode, Context context) {
		LogUtil.e(LOG_TAG, "exceptionCode:" + exceptionCode);
		if (exceptionCode == 8) {
			LogUtil.e("~~", "aaaa");
			Intent intentLogin = new Intent(context, LoginActivity.class);
			intentLogin.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			Bundle bundie = new Bundle();
			bundie.putString("login_back", "share_login_Verification");
			ActivityTaskManager.getInstance().closeAllActivity();
			//
			context.startActivity(intentLogin);
			Toast.makeText(
					context,
					context.getResources().getString(
							R.string.please_login_stor_box_disk),
					Toast.LENGTH_LONG).show();
		}
		else if (exceptionCode == 401) {
			LogUtil.e("~~", "bbbb");
			Intent intentLogin = new Intent(context, LoginActivity.class);
			intentLogin.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			Bundle bundie = new Bundle();
			bundie.putString("login_back", "share_login_Verification");
			ActivityTaskManager.getInstance().closeAllActivity();
			//
			context.startActivity(intentLogin);
			Toast.makeText(
					context,
					context.getResources().getString(R.string.user_NP_Expired)
							+ "(401)", Toast.LENGTH_LONG).show();
		} else if (901 == exceptionCode) {
			ActivityTaskManager.getInstance().closeAllActivity();
			Toast.makeText(context, context.getString(R.string.loginwait_activity_server_not_response)
							+ "(" + exceptionCode + ")", Toast.LENGTH_SHORT).show();
		} else {
			ActivityTaskManager.getInstance().closeAllActivity();
			Toast.makeText(context, context.getString(R.string.loginwait_activity_server_busy)
					+ "(" + exceptionCode + ")", Toast.LENGTH_SHORT).show();
		}
	}
}
